import { Component, OnInit, Input } from '@angular/core';
import { ClueDataService } from '../../../../../@core/service/clue-service/clue-data.service';
import { ClueService } from '../../../../../@core/service/typescript-angular-client/api/clue.service';

@Component({
  selector: 'app-clue-source',
  templateUrl: './clue-source.component.html',
  styleUrls: ['./clue-source.component.scss']
})
export class ClueSourceComponent implements OnInit {

  public depart:any;
  //区域数据
  public areaData: any;
  //省级联动
  public provinces:any[];
  //市级联动 
  public cities:any[];
  //县级联动
  public counties:any[];
  //来源分类字段
  public originType:any;
  //来源投诉举报  （个人&法人）
  public getSelectValue:any = 0;
  addressDetails: any={};
  formJson: any={};
  BizFile: any;
  constructor(
    public clueData:ClueDataService,
    public clueService:ClueService,
  ) {
    this.areaData = clueData.area;
    this.depart = clueData.depart;
   }

  ngOnInit() {

    this.BizFile = this.formJson;
    this.provinces =  this.areaData;
    let {
          ins,
          report,//投诉举报
          depTran,//其它部门移送
          subAss, //上级交办
          other,//其它
      } = this.formJson;
      if (ins == "☑"){
        this.originType = 'ins'
      }else if(report =="☑"){
        this.originType = 'report'
        this.getSelectValue = this.formJson.type;
      }else if(depTran == "☑"){
        this.originType = 'depTran'
      }else if(subAss == "☑"){
        this.originType = 'subAss'
      }else if(other == "☑"){
        this.originType = 'other'
      }
      let province,city,county,detailed,provinceInfo,cityInfo,countyInfo,detailedInfo;
 
      try{
        this.formJson.partyPersionInfo = JSON.parse( this.formJson.partyPersionInfo);
      }catch(e){
      }
      console.log(this.formJson)
      if(this.formJson.partyPersionInfo && this.formJson.partyPersionInfo.addressJson){
        provinceInfo = this.formJson.partyPersionInfo.addressJson.province;
        cityInfo = this.formJson.partyPersionInfo.addressJson.city;
        countyInfo = this.formJson.partyPersionInfo.addressJson.county;
        detailedInfo = this.formJson.partyPersionInfo.addressJson.detailed
      }else if(this.formJson.partyAddress){
        provinceInfo = this.formJson.partyAddress.province;
        cityInfo = this.formJson.partyAddress.city;
        countyInfo = this.formJson.partyAddress.county;
        detailedInfo = this.formJson.partyAddress.detailedInfo;
      }

      //查找返回省级列表
      if(provinceInfo==this.provinces[0]['key']){
          province = provinceInfo;
          this.addressDetails[0] = this.provinces[0].key
      }else{
          province = null;
          this.addressDetails[0]=''
      }

      //查找返回市级列表
      if(cityInfo){
        this.cities = this.provinces[0].children;
        city = cityInfo;
        this.addressDetails[1] = this.cities.filter(cityF=>cityF.key == city)[0].key
      }else{
        this.cities = [];
        city =null;
        this.addressDetails[1] =''
      }
      //查找返回县级列表
      if(countyInfo){
        this.counties = this.cities.filter(cityItem=>city ==cityItem.key)[0].children;
        county = countyInfo;
        this.addressDetails[2] = this.counties.filter(countyF=>county == countyF.key)[0].key
      }else{
        this.addressDetails[2] =''
        this.counties = [];
        county =null;
      }
      if(detailedInfo){
        this.addressDetails[3] = detailedInfo;
      }else{
        this.addressDetails[3] = ''
      }
  }

}
